home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.01 Jan 91 / PieMenus / Pie Source / PieXCMD.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-13  |  2.7 KB  |  127 lines  |  [TEXT/KAHL]

  1. /*
  2.  * File:    PieXCMD.c
  3.  *
  4.  * Purpose: XCMD interface for pie popup menus.
  5.  *
  6.  */
  7. #include    <MacTypes.h>
  8. #include    <MenuMgr.h>
  9. #include    <QuickDraw.h>
  10. #include    <SetUpA4.h>
  11. #include    "HyperXCmd.h"
  12.  
  13.  
  14. /* Local function prototypes. */
  15. pascal    void main(XCmdBlockPtr);
  16.  
  17. /* External function prototypes.*/
  18. int    GetLocOfCardWindow(XCmdBlockPtr, Point *);
  19. Handle    CopyStrToHand(char *);
  20. long    HandleToNum(XCmdBlockPtr, Handle);
  21. void    HandleToPstr(Str255, Handle);
  22. char    *ToCstr(char *);
  23. char    *ToPstr(char *);
  24.  
  25.  
  26.  
  27. #define    ERRORFLAG            (short)    -1
  28. #define    MENU_SEPARATOR        ';'
  29. #define    USAGE     "Usage: put                    \
  30.                 PiePopup(\"Menu;list\",        \
  31.                    font#,fontsize,pat_flag)    \
  32.                 into container"
  33.  
  34.  
  35.  
  36.  
  37. pascal    void
  38. main(XCmdBlockPtr paramPtr)
  39. {
  40.     Str255    menuList;            /* list of menu items */
  41.     int        num_menu_items;     /* # of menu items */
  42.     char    tempStr[32];        /* str scratch buffer */
  43.     int        selection;            /* menu item selected */
  44.     Point    cardWindowLoc;      /* popup positioner */
  45.     int        font = geneva;      /* selected font */
  46.     int        font_size = 10;     /* selected size */
  47.     int        pattern_flag = TRUE;/*use patterns*/
  48.     
  49.  
  50.     /* 
  51.      * LightSpeed C allows global variables to be
  52.      * referenced from A4.
  53.      */
  54.     RememberA0();
  55.     SetUpA4();
  56.         
  57.     /* 
  58.      * Make sure we were called with the proper
  59.      * number of arguments.
  60.      */
  61.     if (paramPtr->paramCount > 4) {
  62.         paramPtr->returnValue = 
  63.                 (Handle) CopyStrToHand(USAGE);
  64.         return;
  65.     }        
  66.                 
  67.     /* 
  68.      * Bias the origin of the popup by 
  69.      * HyperCard's window location 
  70.      */
  71.     if ((GetLocOfCardWindow(
  72.           paramPtr,&cardWindowLoc)) == ERRORFLAG) {
  73.         return;
  74.     }
  75.  
  76.     /* Buffer the menu list. */
  77.     strcpy(menuList, *paramPtr->params[0]);
  78.         
  79.     /* 
  80.      * Strip the features that are supported by
  81.      * the Mac's menu manager but we ignore.
  82.      * These include: line separators, check
  83.      * marks, icons, etc.
  84.      */
  85.     num_menu_items = ConvertMenuList(menuList);
  86.     
  87.     
  88.     /* Obtain any optional parameters */
  89.     if ((paramPtr->paramCount > 1) && 
  90.         (paramPtr->params[1] != '\0'))
  91.         font = (int) HandleToNum(
  92.                     paramPtr, paramPtr->params[1]);
  93.         
  94.     if ((paramPtr->paramCount > 2) && 
  95.         (paramPtr->params[2] != '\0'))
  96.         font_size = (int) HandleToNum(
  97.                     paramPtr, paramPtr->params[2]);
  98.         
  99.     if ((paramPtr->paramCount > 3) &&
  100.         (paramPtr->params[3] != '\0'))
  101.         pattern_flag = (int) HandleToNum(
  102.                     paramPtr, paramPtr->params[3]);
  103.  
  104.  
  105.     /* Put up the pie popup menu */
  106.     selection = DrawPieMenu(cardWindowLoc,
  107.                             menuList, 
  108.                             num_menu_items,
  109.                             font, 
  110.                             font_size,
  111.                             pattern_flag);
  112.         
  113.     /* Return the menu selection to HyperCard */
  114.     NumToStr(paramPtr,
  115.              (long) selection,
  116.              (unsigned char *) tempStr);
  117.     paramPtr->returnValue =
  118.         (Handle) CopyStrToHand(ToCstr((char *) tempStr));
  119.         
  120.     /* Recover original A4 and return */    
  121.     RestoreA4();
  122.     return;
  123. }
  124.  
  125.  
  126.  
  127.